﻿using Castle.DynamicProxy;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;

namespace DigitalHealth.PACS.Common.Interceptor
{
    public class LogInterceptor : IInterceptor
    {
        public ILogger Logger { get; set; }

        public LogInterceptor(ILogger<LogInterceptor> logger)
        {
            Logger = logger;
        }

        public void Intercept(IInvocation invocation)
        {
            Logger.LogInformation("Calling method [{0}] with parameters [{1}]", invocation.Method.Name, Newtonsoft.Json.JsonConvert.SerializeObject(invocation.Arguments));

            invocation.Proceed();

            Logger.LogInformation("Done: result was {0}.", Newtonsoft.Json.JsonConvert.SerializeObject(invocation.ReturnValue));
        }
    }
}
